﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

using BOSS.Framework;
using BOSS.Domain.Security;
using BOSS.Service.Security;

namespace BOSS.Web.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    public class SystemController : AbstractController
    {

        public IRoleService RoleService { get; set; }

        /// <summary>
        /// 角色列表
        /// </summary>
        /// <returns></returns>
        public ActionResult RoleList()
        {
            IList<Role> roles = this.RoleService.SelectAll();
            return View(roles);
        }

        /// <summary>
        /// 角色详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult RoleDetails(int? id)
        {
            if (id == null)
            {
                throw new LogicalException("角色 Id 为空.");
            }

            Role role = this.RoleService.FindById(id.Value);
            if (role == null)
            {
                throw new LogicalException(string.Format("未能找到 Id 为 {0} 的角色.", id));
            }

            PrivilegeGroup privilegeGroup = this.RoleService.GetAssignedPrivileges(role);
            if (privilegeGroup != null)
            {
                ViewData["Privileges"] = privilegeGroup.Privileges.ToList();
            }

            return View(role);
        }
    }
}
